package com.university.mentalhealthplatform.global.rbac.repository;

import com.university.mentalhealthplatform.global.rbac.model.Menu;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import java.util.Set;

@Repository
public interface MenuRepository extends JpaRepository<Menu, Long> {

    // 通过菜单名查找菜单
    Optional<Menu> findByIdentifier(String identifier);

    // 根据 parentMenu 的 ID 查询子菜单
    Set<Menu> findByParentMenu_Id(Long parentId);

    // 查找所有 parentMenu 为空的顶级菜单
    Set<Menu> findByParentMenuIsNull();

    @EntityGraph(attributePaths = {"buttonComponents", "buttonComponents.endpoints"})
    @Query("SELECT m FROM Menu m")
    List<Menu> findAllWithButtonComponentsAndEndpoints();


}
